import * as types from './type'
import {fromJS} from "immutable";

const defaultData = fromJS({
    id: '',
    userId: '',
    pageTitle: '',
    pageContent: '',
    pageCategory: '',
    createDate: '',
    updateDate: '',
    watchCount: 0,
    shareCount: 0,
    likeCount: 0,
    isHidden: '',
    isDel: '',
});

export default (state = defaultData, {type, value}) => {

    switch (type) {
        // header 搜索框
        case types.UPDATE_PAGE_ID:
            return state.set('id', value);

        case types.UPDATE_PAGE_ALL:
            return state.mergeDeep(value);

        case types.CLEAR_PAGE_ALL:
            return state.mergeDeep({
                id: '',
                userId: '',
                pageTitle: '',
                pageContent: '',
                pageCategory: '',
                createDate: '',
                updateDate: '',
                watchCount: 0,
                shareCount: 0,
                likeCount: 0,
                isHidden: '',
                isDel: '',
            });

        default:
            return state;
    }

    return state;
}
